﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBManager.AppCommon.Helper;
using DBManager.DanhMucHeThong.Entities;
namespace DBManager.DanhMucHeThong.DAL
{
    class DanhMuc_DAL
    {
        public DanhMuc_DAL()
        { 
        
        }
        public void DanhMuc_Add(int DanhMucParentID,string TenDanhMuc,string LoaiDanhMuc)
        {
            try
            {
                SQLHelper.ExecuteNonQuery("sp_DanhMuc_Add", CommandType.StoredProcedure,
                                                    new Param("@DanhMucParentID", DanhMucParentID),
                                                    new Param("@TenDanhMuc", TenDanhMuc),
                                                    new Param("@LoaiDanhMuc", LoaiDanhMuc));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DanhMuc_Edit(int DanhMucID, int DanhMucParentID, string TenDanhMuc, string LoaiDanhMuc)
        {
            try
            {
                SQLHelper.ExecuteNonQuery("[sp_DanhMuc_Edit]", CommandType.StoredProcedure,
                                                    new Param("@DanhMucID", DanhMucID),
                                                    new Param("@DanhMucParentID", DanhMucParentID),
                                                    new Param("@TenDanhMuc", TenDanhMuc),
                                                    new Param("@LoaiDanhMuc", LoaiDanhMuc));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DanhMuc_Delete(int DanhMucID)
        {
            try
            {
                SQLHelper.ExecuteNonQuery("[sp_DanhMuc_Delete]", CommandType.StoredProcedure,
                                                    new Param("@DanhMucID", DanhMucID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<DanhMuc_Ent> DanhMuc_GetItems(string LoaiDanhMuc)
        {
            try
            {
               return SQLHelper.GetEntities<DanhMuc_Ent>("[sp_DanhMuc_GetItems]", CommandType.StoredProcedure,
                                                    new Param("@LoaiDanhMuc", LoaiDanhMuc));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DanhMuc_Ent DanhMuc_GetItem(int DanhMucID)
        {
            try
            {
               return SQLHelper.GetEntity<DanhMuc_Ent>("[sp_DanhMuc_GetItem]", CommandType.StoredProcedure,
                                                    new Param("@DanhMucID", DanhMucID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
